package src.Fifteen;

import javax.swing.*;
import java.awt.*;

public class InterruptedSwing extends JFrame {

    Thread thread;

    public static void main(String[] args) {
        InterruptedSwing.init(new InterruptedSwing(),500,500);
    }

    public InterruptedSwing(){
        super();
        final JProgressBar progressBar = new JProgressBar();
        getContentPane().add(progressBar, BorderLayout.NORTH);
        progressBar.setStringPainted(true);
        thread = new Thread(new Runnable() {
            int count = 0;

            @Override
            public void run() {
                while (true){
                    progressBar.setValue(++count);
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        System.out.println("线程被中断");
                    }
                }
            }
        });
        thread.start();
        thread.interrupt();
    }

    public static void init(JFrame jFrame,int width,int height){
        jFrame.setSize(width,height);
        jFrame.setVisible(true);
        jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
}
